package com.truth.lock.factory;

import com.truth.lock.enumeration.TruthLockType;
import com.truth.lock.executor.TruthLockExecutor;

import java.util.EnumMap;
import java.util.Objects;

/**
 * @author truth
 */
@SuppressWarnings("all")
public class TruthExecutorBeanFactory{

    /**
     * TruthLockExecutor当前系统所有的TruthLockExecutor
     */
    private final static EnumMap<TruthLockType, TruthLockExecutor> EXECUTOR_MAP = new EnumMap<>(TruthLockType.class);

    public static void register(TruthLockType lockType, TruthLockExecutor executor) {
        if (Objects.nonNull(lockType) && Objects.nonNull(executor)) {
            EXECUTOR_MAP.putIfAbsent(lockType, executor);
        }
    }


    public static TruthLockExecutor getExecutor(TruthLockType lockType) {
        return EXECUTOR_MAP.get(lockType);
    }
}
